package com.baox.agridata.synchronous.service.impl;

import com.baox.agridata.synchronous.dao.LocalPushDataToScAgricultureMapper;
import com.baox.agridata.synchronous.entity.abutment.XDRBaseDataEntity;
import com.baox.agridata.synchronous.entity.abutment.XDRCertificateEntity;
import com.baox.agridata.synchronous.entity.abutment.XDRHarmlessEntity;
import com.baox.agridata.synchronous.entity.abutment.XDRLiveStockMarketEntity;
import com.baox.agridata.synchronous.service.LocalPushDataToScAgricultureService;
import com.baox.agridata.synchronous.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class LocalPushDataToScAgricultureServiceImpl implements LocalPushDataToScAgricultureService {

    @Autowired
    private LocalPushDataToScAgricultureMapper localPushDataToScAgricultureMapper;

    /**
     * 基础数据的查询推送
     *
     * @return
     */
    @Override
    public List<XDRBaseDataEntity> selectBaseDataToScAgriculture() {
        return localPushDataToScAgricultureMapper.selectBaseDataToScAgriculture();
    }

    @Override
    public List<XDRHarmlessEntity> selectHarmlessData() {
        return localPushDataToScAgricultureMapper.selectHarmlessData();
    }

    @Override
    public List<XDRLiveStockMarketEntity> selectLiveStockMarketData() {
        List<XDRLiveStockMarketEntity> xdrLiveStockMarketDTOEntities = localPushDataToScAgricultureMapper.selectLiveStockMarketData();
        for (XDRLiveStockMarketEntity xdrData : xdrLiveStockMarketDTOEntities) {
            List<Integer> category = new ArrayList<>();
            String animal = xdrData.getAnimal();
            if (!StringUtils.isEmpty(animal)) {
                String[] split = animal.split(",");
                for (String an : split) {
                    category.add(StringUtil.AnimalTypeTurn(an.trim()));
                }
            }
            xdrData.setCategory(category);
            xdrData.setAnimal(null);
        }
        return xdrLiveStockMarketDTOEntities;
    }

    @Override
    public List<XDRCertificateEntity> selectCertificateData() {
        return localPushDataToScAgricultureMapper.selectCertificateData();
    }

    @Override
    public List<XDRCertificateEntity> selectOutProvinceData() {
        return localPushDataToScAgricultureMapper.selectOutProvinceData();
    }

    @Override
    public List<XDRCertificateEntity> selectInProvinceData() {
        return localPushDataToScAgricultureMapper.selectInProvinceData();
    }
}
